/*****************************************************************
Mix3D WebGL Game Engine
Copyright (c) fantasy ( fantasy.x2x@gmail.com )
Listens:
Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt
 ****************************************************************/
/**
 * @Desc    : node
 * @Author  : fantasy(fantasy.x2x@gmail.com)
 
 scene:  Node
          |
          |--Spatial( mesh, particle, light, camera)
          |--Node
              |
              |--Spatial
              |--Spatial
              |--Node
              |
          |
          |--Node    
 */
//////////////////////////////////////////////////////////////////
if(typeof(Mix3D) === 'undefined')
{
  Mix3D = {};
};
(function(Mix3D){
//////////////////////////////////////////////////////////////////
Mix3D.Node = function()
{
  Mix3D.Spatial.call(this);
  this.children =[];
};

Mix3D.Node.prototype.constructor = Mix3D.Node;
Mix3D.Node.prototype.className = 'Node';

Mix3D.Node.prototype.add = function(obj)
{
  if(obj === this)
  {
    Mix3D.warning('An object can\'t be added as a child of itself.');
  }
  if(obj.parent !== undefined)
  {
    obj.parent.remove(obj);
  }
  obj.parent = this;
  this.children.push(obj);
};

Mix3D.Node.prototype.remove = function(obj)
{
  var idx = this.children.indexOf(obj);
  if(idx !== -1)
  {
    obj.parent = undefined;
    this.children.splice(idx, 1);
  }
};

Mix3D.Node.prototype.updateWorldData = function(deltaTime, elpasedTime)
{
  for( var i=0,len=this.children.length; i<len; ++i)
  {
    this.children[i].update(deltaTime, elpasedTime);
  }
};

Mix3D.Node.prototype.updateWorldBound = function( ) 
{
  this.worldBound.setCenter(0,0,0).setRadius(0);
  for( var i=0,len=this.children.length; i<len; ++i)
  {
    thos.worldBound.mearge(this.children[i].worldBound);
  }
};

Mix3D.Node.prototype.getVisibleObject = function( culler, isNoCull) 
{
  for( var i=0,len=this.children.length; i<len; ++i)
  {
    this.children[i].getVisibleObject(culler, isNoCull);
  }
};

Mix3D.protoCopy(Mix3D.Spatial, Mix3D.Node);
//////////////////////////////////////////////////////////////////
})(Mix3D);// end of function(Mix3D)